package com.jiuyue.stream.controller;

import java.util.Arrays;
import java.util.List;
import static java.util.Comparator.comparing;
import static java.util.stream.Collectors.toList;
import org.springframework.stereotype.Controller;
import com.jiuyue.stream.entity.Dish;

@Controller
public class Java8StreamController {
	/**
	 * java8 Stream API
	 * @param args
	 */
	public static void main(String[] args) {
		//组装实现需要的数据
		List<Dish> menu =Arrays.asList(
				new Dish("pork", false, 800,Dish.Type.MEAT),
				new Dish("beef", false, 700,Dish.Type.MEAT),
				new Dish("chicken", false, 400,Dish.Type.MEAT),
				new Dish("french fries", true, 530,Dish.Type.OTHER),
				new Dish("rich", true, 350,Dish.Type.OTHER),
				new Dish("season fruit", true, 120,Dish.Type.OTHER),
				new Dish("pizza", true, 550,Dish.Type.OTHER),
				new Dish("prawns", false, 300,Dish.Type.FISH),
				new Dish("salmon", false, 450,Dish.Type.FISH)
				);
		//Stream api操作集合 需要获取低卡路里食物的名字集合  低卡路里的标准 卡路里低于 400
		List<String> lowCaloriesDishName =menu.stream().
				filter(d->d.getCalories()<400)
				.sorted(comparing(Dish::getCalories))
				.map(Dish::getName)
				.collect(toList());
		
		System.out.println("获取的低卡路里食物的名字集合为"+lowCaloriesDishName);
	}
	
	
	
}
